import commit from "./hooks/commit";
import publish from "./hooks/publish";
import { readdirSync } from "fs";

(async function() {
  // fixme: 产物中包含promise.withResolvers，导致代码无法按预期执行，查阅了资料没有找到去除的方法，暂时先将代码进行清洁
  const distDir = readdirSync('./dist')
  const codeUrl = distDir.find(k => /index.{1,}.js/.test(k))
  Bun.write(
    `./dist/${codeUrl}`,
    await Bun.file(`./dist/${codeUrl}`).text().then(k => k.replace(/Promise.withResolvers\(\)/g, 'Promise'))
  )

  await commit();
  await publish();

  console.log('💚 💛 🧡 🩷    deploy success !');
})()
